<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('【请填写功能名称】列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <p>项目名称：</p>
                                <input type="text" name="onlineExperimentName"/>
                            </li>
                            <li>
                                <p>项目网址：</p>
                                <input type="text" name="onlineExperimentUrl"/>
                            </li>
                            <li>
                                <p>专业：</p>
                                <div class="col-sm-8">
                                    <!--<input name="profession" th:field="*{profession}" class="form-control" type="text">-->
                                    <select name="profession" id="profession" th:with="dicts=${@dict.getType('sys_profession')}">
                                        <option value="">请选择</option>
                                        <option th:each="dict:${dicts}" th:value="${dict.dictValue}" th:text="${dict.dictLabel}"></option>
                                    </select>
                                </div>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <!--<div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="system:onlineExperiment:add">
                    <i class="fa fa-plus"></i> 添加
                </a>
                <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="system:onlineExperiment:edit">
                    <i class="fa fa-edit"></i> 修改
                </a>
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="system:onlineExperiment:remove">
                    <i class="fa fa-remove"></i> 删除
                </a>
                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="system:onlineExperiment:export">
                    <i class="fa fa-download"></i> 导出
                 </a>
            </div>-->
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('system:onlineExperiment:edit')}]];
        var removeFlag = [[${@permission.hasPermi('system:onlineExperiment:remove')}]];
        var prefix = ctx + "system/OnlineExperimentTend";

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "实验项目内容",
                columns: [{
                    checkbox: true
                },
                {
                   field : 'onlineExperimentImg',
                   formatter : function (value,row,index) {
                        return "<img src='"+ctx+value+"' style='width: 192px;height: 108px'/>"
                   }
                },
                {
                    field : 'onlineExperimentId', 
                    title : '项目编号',
                    visible: false
                },
                {
                    field : 'onlineExperimentName', 
                    title : '项目名称'
                },
                {
                    field : 'onlineExperimentUrl', 
                    title : '项目网址'
                },
                    {
                        visible: editFlag == 'hidden' ? false : true,
                        title: '是否开放实验',
                        align: 'center',
                        formatter: function (value, row, index) {
                            return statusTools(row);
                        }
                    },
                {
                    field : 'professionName',
                    title : '专业'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.editTab(\'' + row.onlineExperimentId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });


        /* 实验开放的状态 */
        function statusTools(row) {
            if (row.ifOpen == 2) {
                return '<i class=\"fa fa-toggle-off text-info fa-2x\" onclick="enable(\'' + row.onlineExperimentId + '\')"></i> ';
            } else {
                return '<i class=\"fa fa-toggle-on text-info fa-2x\" onclick="disable(\'' + row.onlineExperimentId + '\')"></i> ';
            }
        }

        /* 实验关闭 */
        function disable(value) {
            $.modal.confirm("确认要关闭实验？", function() {
                $.operate.post(prefix + "/edit", { "onlineExperimentId": value, "ifOpen": 2 });
            })
        }

        /* 实验开放 */
        function enable(value) {
            $.modal.confirm("确认要开放实验？", function() {
                $.operate.post(prefix + "/edit", { "onlineExperimentId": value, "ifOpen": 1 });
            })
        }
    </script>
</body>
</html>